//
//  LCInviteFriendViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/3/24.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCInviteFriendViewController.h"
#import "LCUserModel.h"
#import "LCInviteExplainView.h"
#import "XWXShareHelper.h"
#import "ImageBrowserViewController.h"

#import "LCInvitePosterViewController.h"
#import "LCInviteAdViewController.h"
@interface LCInviteFriendViewController ()

@property (weak, nonatomic) IBOutlet UILabel *shareCodeLb;

@property (weak, nonatomic) IBOutlet UIImageView *qrCodeImgV;


@end

@implementation LCInviteFriendViewController


-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.shareCodeLb drawDashedBorderWith:0.5f dashPattern:@[@2,@2] lineColor:[UIColor colorWithHexString:@"#999999"]];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    LCUserModel * userModel = [LCUserModel mj_objectWithKeyValues:LCUserDefGet(UserInfo)];
    self.shareCodeLb.text = userModel.share.code;
    [self.qrCodeImgV sd_setImageWithURL:[NSURL URLWithString:userModel.share.qrcode]];
}

- (IBAction)copyBtnAction:(UIButton *)sender {
    UIPasteboard *pab = [UIPasteboard generalPasteboard];
    LCUserModel * userModel = [LCUserModel mj_objectWithKeyValues:LCUserDefGet(UserInfo)];
    NSString*string = kFORMAT(@"%@",userModel.share.code);
    [pab setString:string];
    if(pab == nil) {
        [self showErrorText:@"复制失败"];
    }else{
        [self showSuccessText:@"复制成功"];
    }
}

- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)pushBtnAction:(UIButton *)sender {
    LCInviteAdViewController * vc = [LCInviteAdViewController xx_instantiateFromStoryboardNamed:@"Invite"];
    [self.navigationController pushViewController:vc animated:YES];
}

//邀请说明
- (IBAction)navRightAction:(UIButton *)sender {
    LCInviteExplainView * alertView = [[LCInviteExplainView alloc] initForNib];
    [alertView show];
}

- (IBAction)wechatBrnAction:(UIButton *)sender {
    LCUserModel * userModel = [LCUserModel mj_objectWithKeyValues:LCUserDefGet(UserInfo)];
    
    [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:userModel.share.qrcode] completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
        [XWXShareHelper shareWithController:self andItems:@[image] andCompletion:^(BOOL success) {
            if (success) {
                [self showSuccessText:@"分享成功!"];
            }else{
                [self showErrorText:@"分享失败!"];
            }
        }];
    }];
}

- (IBAction)linkShareBtnAction:(UIButton *)sender {
    LCUserModel * userModel = [LCUserModel mj_objectWithKeyValues:LCUserDefGet(UserInfo)];
    UIPasteboard *pab = [UIPasteboard generalPasteboard];
    [pab setString:userModel.share.url];
    if(pab == nil) {
        [self showErrorText:@"复制失败"];
    }else{
        [self showSuccessText:@"复制成功"];
    }
}


@end
